/**
 * ErrnoMessage
 * Copyright (C) 2009 Hajime Yoshimori <RoarLudros@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <ErrnoMessage>
#include <DragonInit>

#include <cerrno>
#include <cstring>

#include <config.h>

dragon::ErrnoMessage::ErrnoMessage(int _errno) {
  type = dragon::ErrnoMessage::error;
  normal_msg = strerror(_errno);
  dragon_msg = dragon_strerror(_errno);
  if(dragon_msg == "") {
	dragon_msg = normal_msg;
  }
}

dragon::ErrnoMessage::~ErrnoMessage() {
//  this->~DragonMessage();
}

std::string dragon::ErrnoMessage::getMessage(dragon::DragonMessage::msg_word word) const throw() {
  switch(word) {
	case dragon:
	  return dragon_msg;
	case normal:
	default:
	  return normal_msg;
 }
}

const char* dragon::ErrnoMessage::dragon_strerror(int _errno) throw() {
  switch(_errno) {
	case 0:
	  return d_("No problem occured!").c_str();
	case E2BIG:
	  return d_("I can\'t accept such long parameter list.").c_str();
	case EACCES:
	  return d_("I\'m not permitted to do that.").c_str();
	case EADDRINUSE:
	  return d_("That address is already used.").c_str();
	case EADDRNOTAVAIL:
	  return d_("That address is not available.").c_str();
	case EAFNOSUPPORT:
	  return d_("That address family is not supported.").c_str();
	case EAGAIN:
	  return d_("That library is not available temporarily.").c_str();
#ifdef EBADE
	case EBADE:
	  return d_("That exchange is not valid.").c_str();
#endif
	case EBADF:
	  return d_("That file handle is not valid.").c_str();
#ifdef EBADFD
	case EBADFD:
	  return d_("The status of that file handle is corrupted.").c_str();
#endif
	case EBADMSG:
	  return d_("That message is not valid.").c_str();
#ifdef EBADR
	case EBADR:
	  return d_("That request handle is not valid.").c_str();
#endif
#ifdef EBADRQC
	case EBADRQC:
	  return d_("That request code is not valid.").c_str();
#endif
#ifdef EBADSLT
	case EBADSLT:
	  return d_("That slot is not valid.").c_str();
#endif
	case EBUSY:
	  return d_("That library is busy.").c_str();
	case ECANCELED:
	  return d_("That operation is canceled.").c_str();
	case ECHILD:
	  return d_("There are no child dragon.").c_str();
#ifdef ECHRNG
	case ECHRNG:
	  return d_("The channel is out of range.").c_str();
#endif
#ifdef ECOMM
	case ECOMM:
	  return d_("Communication failed.").c_str();
#endif
	case ECONNABORTED:
	  return d_("That connection is aborted by opponent castle.").c_str();
	case ECONNREFUSED:
	  return d_("That connection is refused by opponent castle.").c_str();
	case ECONNRESET:
	  return d_("That connection is resetted by opponent castle.").c_str();
	case EDEADLK:
	  return d_("We avoided the dead lock of the library.").c_str();
	case EDESTADDRREQ:
	  return d_("Destination address is not specified.").c_str();
#ifdef EDOM
	case EDOM:
	  return d_("That number is out of range in this function.").c_str();;
#endif
	case EDQUOT:
	  return d_("I encountered the limitation of your library quota.").c_str();
	case EEXIST:
	  return d_("That file is exist.").c_str();
	case EFAULT:
	  return d_("That address is not valid.").c_str();
	case EFBIG:
	  return d_("That file is too big.").c_str();
#ifdef EHOSTDOWN
	case EHOSTDOWN:
	  return d_("The opponent castle is not alive.").c_str();
#endif
	case EHOSTUNREACH:
	  return d_("I couldn\'t go to the opponent castle.").c_str();
	case EIDRM:
	  return d_("That identification is removed.").c_str();
	case EILSEQ:
	  return d_("That string is not valid.").c_str();
	case EINPROGRESS:
	  return d_("I\'m processing, please wait.").c_str();
	case EINTR:
	  return d_("Other dragon or you interrupted me when I\'m doing that function.").c_str();
	case EINVAL:
	  return d_("That parameter is not valid.").c_str();
	case EIO:
	  return d_("I couldn\'t read from or write to file or receive from or send to other castle.").c_str();
	case EISCONN:
	  return d_("Disconnect before do this.").c_str();
	case EISDIR:
	  return d_("That is a directory, not a file.").c_str();
#ifdef EISNAM
	case EISNAM:
	  return d_("That has a name. Remove the name before do this.").c_str();
#endif
#ifdef EKEYEXPIRED
	case EKEYEXPIRED:
	  return d_("That key is expired. Make new key or try with other key.").c_str();
#endif
#ifdef EKEYREJECTED
	case EKEYREJECTED:
	  return d_("That key is rejected by the opponent castle.").c_str();
#endif
#ifdef EKEYREVOKED
	case EKEYREVOKED:
	  return d_("That key is revoked. Try with other key.").c_str();
#endif
	// EL2HLT
	// EL2NSYNC
	// EL3HLT
	// EL3RST
	// ELIBBAD
	// ELIBMAX
	// ELIBSCN
	// ELIBEXEC
	case ELOOP:
	  return d_("There are meny symbolic links in that path.").c_str();
#ifdef EMEDIUMTYPE
	case EMEDIUMTYPE:
	  return d_("That medium type is wrong.").c_str();
#endif
	case EMFILE:
	  return d_("Many files opened. Close some of them before do this.").c_str();
	case EMLINK:
	  return d_("There are many links.").c_str();
	case EMSGSIZE:
	  return d_("The message is too long.").c_str();
	// EMULTIHOP
	case ENAMETOOLONG:
	  return d_("That file name is long. Shorten it.").c_str();
	case ENETDOWN:
	  return d_("This castle is isolated.").c_str();
	case ENETRESET:
	  return d_("The opponent castle canceled the communication.").c_str();
	case ENETUNREACH:
	  return d_("I could\'nt find the way to the opponent castle.").c_str();
	case ENFILE:
	  return d_("Many files is opened in our castle.").c_str();
	case ENOBUFS:
	  return d_("There are no data space in the temporary board.").c_str();
	case ENODATA:
	  return d_("There are no messages.").c_str();
	case ENODEV:
	  return d_("There are no such device.").c_str();
	case ENOENT:
	  return d_("That file or book is not in the library.").c_str();
	case ENOEXEC:
	  return d_("I couldn\'t execute that file.").c_str();
#ifdef ENOKEY
	case ENOKEY:
	  return d_("Requested key is not available.").c_str();
#endif
	case ENOLCK:
	  return d_("I couldn\'t lock that file.").c_str();
	case ENOLINK:
	  return d_("That link is broken.").c_str();
#ifdef ENOMDIUM
	case ENOMEDIUM:
	  return d_("There are no medium.").c_str();
#endif
	case ENOMEM:
	  return d_("There are no data space in the board.").c_str();
	case ENOMSG:
	  return d_("There are no message that matches the requested type.").c_str();
#ifdef ENONET
	case ENONET:
	  return d_("This castle is isolated.").c_str();
#endif
#ifdef ENOPKG
	case ENOPKG:
	  return d_("There are no package in this castle.").c_str();
#endif
	case ENOPROTOOPT:
	  return d_("That comminucation type is not available.").c_str();
	case ENOSPC:
	  return d_("Disc is full.").c_str();
	case ENOSR:
	  return d_("Specified stream, disk or other resource is not found.").c_str();
	case ENOSTR:
	  return d_("That isn\'t stream.").c_str();
	case ENOSYS:
	  return d_("This function is not implemented.").c_str();
#ifdef ENOTBLK
	case ENOTBLK:
	  return d_("That requires block device. It is not found.").c_str();
#endif
	case ENOTCONN:
	  return d_("There is not the opponent castle.").c_str();
	case ENOTDIR:
	  return d_("That is not a directory.").c_str();
	case ENOTEMPTY:
	  return d_("That directory is not empty. Clean the directory and retry it.").c_str();
	case ENOTSOCK:
	  return d_("That is not a door (socket).").c_str();
	case ENOTSUP:
	  return d_("I couldn\'t operate that.").c_str();
	case ENOTTY:
	  return d_("This function must be used with \"you\".").c_str();
	case ENOTUNIQ:
	  return d_("That name is not unique.").c_str();
	case ENXIO:
	  return d_("That device or address is not found.").c_str();
#if EOPNOTSUPP != ENOTSUP
	case EOPNOTSUPP:
	  return d_("I couldn\'t operate that in the socket.").c_str();
#endif
	case EOVERFLOW:
	  return d_("The inputted value is very big or large, and I couldn\'t store it.").c_str();
	case EPERM:
	  return d_("I\'m not permitted to do that.").c_str();
	// EPFNOSUPPORT
	case EPIPE:
	  return d_("That pipe is broken.").c_str();
	case EPROTO:
	  return d_("Communication failed.").c_str();
	case EPROTONOSUPPORT:
	  return d_("That is not valid communication type.").c_str();
	case ERANGE:
	  return d_("The result is too big and I couldn\'t handle it.").c_str();
#ifdef EREMCHG
	case EREMCHG:
	  return d_("The address of the opponent castle changed.").c_str();
#endif
#ifdef EREMOTEIO
	case EREMOTEIO:
	  return d_("Communication failed at the opponent castle.").c_str();
#endif
#ifdef ERESTART
	case ERESTART:
	  return d_("That function is suspended and required to restart.").c_str();
#endif
	case EROFS:
	  return d_("That file is read only, I cannot write to it.").c_str();
#ifdef ESHUTDWN
	case ESHUTDOWN:
	  return d_("The opponent castle is not alive and I couldn\'t send data.").c_str();
#endif
	case ESPIPE:
	  return d_("You cannot seek on pipe.").c_str();
	case ESTALE:
	  return d_("That file handle is old.").c_str();
#ifdef ESTRPIPE
	case ESTRPIPE:
	  return d_("Communication failed.").c_str();
#endif
	case ETIME:
	  return d_("The time is out. You may retry it.").c_str();
	case ETIMEDOUT:
	  return d_("That operation is timed out.").c_str();
	case ETXTBSY:
	  return d_("That file is in use.").c_str();
	// EUCLEAN
	// EUNATCH
#ifdef EUSERS
	case EUSERS:
	  return d_("There are many users in this castle and no more users are not acceptable.").c_str();
#endif
#if EWOULDBLOCK != EAGAIN
	case EWOULDBLOCK:
	  return d_("That operation would be blocked.").c_str();
#endif
	case EXDEV:
	  return d_("That is invalid link.").c_str();
#ifdef EXFULL
	case EXFULL:
	  return d_("The conversion table is full.").c_str();
#endif
	default:
	  return "";
  }
}

